var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({ __proto__: [] } instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
            function (t, e) {
                a(t, e);
                function o() {
                    this.constructor = t;
                }
                t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
            }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", { value: !0 });
var r = t("UIConfig"),
    s = t("UIManager"),
    c = t("GameEm"),
    p = t("TimeViewNode"),
    l = t("BaseClick"),
    d = cc._decorator,
    u = d.ccclass,
    h = d.property,
    f =
        (d.menu,
            (function (t) {
                i(e, t);
                function e() {
                    var e = (null !== t && t.apply(this, arguments)) || this;
                    e.timeCom = null;
                    e.viewNode = null;
                    e.freeNode = null;
                    e.adNode = null;
                    e.addLab = null;
                    e.canClick = !0;
                    e.canClickNode = !1;
                    e.isFillStatus = !1;
                    return e;
                }
                e.prototype.onLoad = function () {
                    t.prototype.onLoad.call(this);
                    this.viewNode.active = !1;
                    if (GameDataValue.getLastLv() >= 1) {
                        EVUIEffView.on(EVUIEffView.firstDlgEv, this.openGuild.bind(this));
                        this.canClickNode = GuildCache.isOverOnceGuid(GuildCache.oncecheckId[1][0]);
                    }
                    this.checkRed();
                    EVUIEffView.on(EVUIEffView.updateBtn, this.updateTime.bind(this), this);
                    this.updateTime();
                };
                e.prototype.openGuild = function () {
                    if (!CacheDataManager.isViewAdBtn && GameDataValue.getLastLv() >= 1) {
                        CacheDataManager.isViewAdBtn = !0;
                        this.canClickNode = !0;
                        if (
                            !GuildCache.isOverOnceGuid(GuildCache.oncecheckId[1][0]) &&
                            GuildCache.checkKey != GuildCache.oncecheckId[1][0]
                        ) {
                            GuildCache.checkKey = GuildCache.oncecheckId[1][0];
                            CacheDataManager.isUpdateRed = !0;
                            GuildCache.openGuildView({ kid: 1 });
                        }
                    }
                };
                e.prototype.onDestroy = function () {
                    EVUIEffView.offTarget(this);
                };
                e.prototype.canViewNode = function () {
                    return GameDataValue.getLastLv() >= 1 && CacheDataManager.isViewAdBtn;
                };
                e.prototype.checkRed = function () {
                    GameDataValue.getLastLv() >= 1 && (CacheDataManager.isViewAdBtn = !0);
                    if (this.canViewNode()) {
                        this.viewNode.active = !0;
                        this.updateTime();
                    }
                };
                e.prototype.moveTimeCall = function (t) {
                    if ("1" == t) {
                        if (this.isFillStatus) return;
                        if (!CacheDataManager.getRedData(c.RedEm.adRed5Min)) {
                            CacheDataManager.setRedData(c.RedEm.adRed5Min, !0);
                            CacheDataManager.isUpdateRed = !0;
                        }
                        this.timeCom.node.active = !1;
                        if (CacheDataManager.getLastAdViewGameTime(c.GameTimeKind.viewAdNextAddTime) < Date.now()) {
                            CacheDataManager.adMul = this.getAddMulValue();
                            CacheDataManager.updateCostDataView = !0;
                        }
                        this.isFillStatus = !0;
                    } else {
                        if (CacheDataManager.getRedData(c.RedEm.adRed5Min)) {
                            CacheDataManager.setRedData(c.RedEm.adRed5Min, !1);
                            CacheDataManager.isUpdateRed = !0;
                        }
                        this.timeCom.node.active = !0;
                        this.isFillStatus = !1;
                    }
                };
                e.prototype.clickAd = function () {
                    this._TouchCancel();
                };
                e.prototype._TouchCancel = function () {
                    var t = this;
                    if (this.canClickNode && this.viewNode.active)
                        if (GuildCache.isOverOnceGuid(GuildCache.oncecheckId[1][0])) {
                            var e = Date.now() - CacheDataManager.getLastAdViewGameTime(c.GameTimeKind.gameClickDouble);
                            this.canClick && e >= CacheDataManager.addMulTimeCd
                                ? BannerAd.Instance.ShowVideo(() => {
                                    CacheDataManager.setLastAdViewGameTime(
                                        c.GameTimeKind.gameClickDouble,
                                        Date.now()
                                    );
                                    QReport.send("2003");
                                    t.addNextTime();
                                })
                                // AdView.showRewardVedioAd(
                                //       function (e) {
                                //           if (e) {
                                //               CacheDataManager.setLastAdViewGameTime(
                                //                   c.GameTimeKind.gameClickDouble,
                                //                   Date.now()
                                //               );
                                //               QReport.send("2003");
                                //               t.addNextTime();
                                //           }
                                //       },
                                //       "2",
                                //       "view ad node"
                                //   )
                                : s.default.open(r.UIID.UIToast, { msg: "冷却中" });
                        } else {
                            CacheDataManager.setLastAdViewGameTime(c.GameTimeKind.gameClickDouble, Date.now());
                            GuildCache.overOnceGuid(GuildCache.oncecheckId[1][0]);
                            this.addNextTime();
                            this.updateTime();
                        }
                };
                e.prototype.getAddMulValue = function () {
                    return CacheDataManager.getLvUpgradeValueData(c.UpgradeData.viewAdMul);
                };
                e.prototype.addNextTime = function () {
                    CacheDataManager.adMul = this.getAddMulValue();
                    var t = CacheDataManager.getLastAdViewGameTime(c.GameTimeKind.viewAdNextAddTime),
                        e = Math.max(0, t - Date.now()),
                        o = CacheDataManager.getLvUpgradeValueData(c.UpgradeData.viewAdTime),
                        a = Math.floor(CacheDataManager.addMulTime * o) + e;
                    a = Date.now() + a;
                    CacheDataManager.setLastAdViewGameTime(c.GameTimeKind.viewAdNextAddTime, a);
                    CacheDataManager.updateCostDataView = !0;
                    this.updateTime();
                };
                e.prototype.setIsAd = function (t) {
                    this.adNode.active = t;
                    this.freeNode.active = !t;
                };
                e.prototype.updateTime = function () {
                    var t = this.getAddMulValue();
                    CacheDataManager.adMul > 1 && (CacheDataManager.adMul = t);
                    this.addLab.string = "×" + t;
                    if (this.viewNode.active && !GuildCache.isOverOnceGuid(GuildCache.oncecheckId[1][0])) this.setIsAd(!1);
                    else {
                        this.setIsAd(!0);
                        var e = Date.now(),
                            o = CacheDataManager.getLastAdViewGameTime(c.GameTimeKind.viewAdNextAddTime),
                            a = Math.max(0, o - e);
                        this.timeCom.checkView(e, a, this.moveTimeCall.bind(this));
                    }
                };
                n([h(p.default)], e.prototype, "timeCom", void 0);
                n([h(cc.Node)], e.prototype, "viewNode", void 0);
                n([h(cc.Node)], e.prototype, "freeNode", void 0);
                n([h(cc.Node)], e.prototype, "adNode", void 0);
                n([h(cc.Label)], e.prototype, "addLab", void 0);
                return n([u], e);
            })(l.default));
o.default = f;
